package com.ztgf.commodity.api.client;

import com.ztgf.commodity.models.service.ICommoditySpecificationRelationService;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: chenyu.wang
 * date: 2020-06-08 16:56
 * Description: 商品规格属性表
 */
@RestController
@RequestMapping("/api/commoditySpecificationRelation")
@Slf4j
@Api(value = "CommoditySpecificationRelationController", tags = "商品规格属性价格表接口")
public class CommoditySpecificationRelationController {

    @DubboReference
    private ICommoditySpecificationRelationService commoditySpecificationRelationService;

    @PostMapping(value = "/getGoodsSkuPrice")
    @ApiOperation(value = "商品属性价格信息", notes = "商品属性价格信息")
    public Result getGoodsSkuPrice(Long id, String ids) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return new Result<>(commoditySpecificationRelationService.getGoodsSkuPrice(id, ids));
    }

    @PostMapping(value = "/updateInventory")
    @ApiOperation(value = "添加商品库存接口", notes = "添加商品库存接口")
    public Result updateInventory(Long id, Integer num) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean flag = commoditySpecificationRelationService.updateInventory(id, num);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }

    @PostMapping(value = "/batchUpdateInventory")
    @ApiOperation(value = "批量修改库存", notes = "批量修改库存")
    public Result batchUpdateInventory(String ids, Integer num) {
        if (!StringUtils.isNotBlank(ids)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean flag = commoditySpecificationRelationService.batchUpdateInventory(ids, num);
        if (flag) {
            return new Result<>();
        }
        return new Result<>(CodeEnum.FAIL_100007);
    }
}
